/*
 * Tic-Tac-Toe - Turn-based strategy game
 * Copyright 2008, 2009 Shayne Riley and Paul Maseberg
 *
 * Tic-Tac-Toe is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Tic-Tac-Toe is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Tic-Tac-Toe.  If not, see <http://www.gnu.org/licenses/>
 * or write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * To contact the authors on questions or issues regarding the license,
 * you may send an email to <shayner at gmail dot com>
 */

#include "TitleScreen.h"
#include "MenuButton.h"
#include "Button.h"
#include <iterator>
#include <list>
#include <string>

using namespace std;

TitleScreen::TitleScreen(Graphics *gfx, Audio *aud)
: mGfx(gfx), mAud(aud), mSettingDifficulty(GameBoard::EASY)
{

}

TitleScreen::~TitleScreen()
{
}

void TitleScreen::perform()
{
    bool shouldLoop = true;
    bool done = false;

    MenuButton easy = MenuButton(mGfx, "vs. Easy Computer", 200, 280, 240, 48);
    MenuButton hard = MenuButton(mGfx, "vs. Hard Computer", 200, 216, 240, 48);
    Button chad = Button(170, 116, 120, 14);
    Button proggers = Button(170, 131, 270, 14);

    mAud->play(Audio::SONG_TITLE);

    while (shouldLoop && !done)
    {
        shouldLoop = mGfx->drawGame();

        mGfx->setColor(0, 0, 0, 1);
        mGfx->drawTexture(&mGfx->textureTitle, 64, 351);

        mGfx->drawTexture(&mGfx->texturePezad, 24, 24);

        mGfx->setColor(0, 0, 0, 0.6f);
        mGfx->setColor(0, 0, 0, 1);
        mGfx->setFontSize(12);
        if (proggers.isHovering() || proggers.isPressing())
        {
            mGfx->setFontSize(13);
        }
        mGfx->drawText("Progging: Shayne Riley, Paul Maseberg", 170, 130);
        mGfx->setFontSize(12);
        if (chad.isHovering() || chad.isPressing())
        {
            mGfx->setFontSize(13);
        }
        mGfx->drawText("Audio: Chad Nigh", 170, 115);
        mGfx->setFontSize(12);
        mGfx->drawText("So called \"art\": Shayne Riley", 170, 100);
        // Copyrights
        mGfx->drawText("Copyright 2008 Shayne Riley and Paul Maseberg", 170, 80);
        mGfx->drawText("Distributed under the terms of the GNU General Public License", 170, 65);
        mGfx->drawText("Music Copyright 2008 Chad Nigh", 170, 40);
        mGfx->drawText("Distributed under the terms of the", 170, 25);
        mGfx->drawText("Creative Commons Attribution-Share Alike 3.0 US License", 170, 10);
        mGfx->setFontSize(20);

        if (0 < mGfx->controls.size())
        {
            list<Graphics::Mouse>::const_iterator iter;

            for (iter = mGfx->controls.begin(); iter != mGfx->controls.end(); iter++)
            {
                easy.update(*iter);
                hard.update(*iter);
                chad.update(*iter);
                proggers.update(*iter);
                if (easy.isClicked())
                {
                    mSettingDifficulty = GameBoard::EASY;
                    done = true;
                }
                if (hard.isClicked())
                {
                    mSettingDifficulty = GameBoard::HARD;
                    done = true;
                }
                if (chad.isClicked())
                {
                    mAud->play(Audio::SONG_SECRET);
                }
                if (proggers.isClicked())
                {
                    mGfx->showFPS = !mGfx->showFPS;
                }
            }
        }
        easy.draw();
        hard.draw();

        mGfx->endFrame();
    }
}

GameBoard::Difficulty TitleScreen::getSettingDifficulty()
{
    return mSettingDifficulty;
}

